package com.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.util.ConfigUtil;

import com.util.BODY;
import com.util.DateUtil;
import com.util.HttpRequest;
import com.util.JSONUtil;
import com.util.OpenKey;
import com.util.ReadConfig;
import com.util.SessionInfo;

/**
 * 缴存历史记录
 * @author 
 */
@Controller
@RequestMapping("/hjgncontroller")
public class HjGncontroller {

	private static final Logger logger = Logger.getLogger(HjGncontroller.class);
	Map map  = new HashMap();
	List list = new ArrayList();
	  
	@RequestMapping("/test")
	@ResponseBody
	public String entryinterface(HttpServletRequest request,HttpSession session, HttpServletResponse response , String limit ,String id,String start,String end) throws IOException, ParseException{
		//读取配置文件路劲
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		String interfaceUrl = ReadConfig.readValue();
		OpenKey opk=new OpenKey();
		Map reqMap = new HashMap();
		//接口编码
		reqMap.put("AUTHORITY", "YBGJJ177");
		//接口参数
		BODY body=new BODY();
		body.setDWZH(sessionIn.getDWZH());
		reqMap.put("BODY",body);
		reqMap.put("OpenKey",sessionIn.getKEY());
		String  result = opk.getOpenKey(reqMap, session);
		Map retMap = JSONUtil.toMap(result);
		retMap = (Map) retMap.get("body");
    	List retlist = (List)retMap.get("RETDATA");
		if(result != null){
			Map resMap = JSONUtil.toMap(result);
				map.put("code", 0); 
				map.put("msg", resMap.get("RETURNDESC"));;
				map.put("data",retlist);
				list.add(resMap);
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
		}
		return null;
	}
	
	@RequestMapping("/test1")
	@ResponseBody
	public String entryinterface1(HttpServletRequest request,HttpSession session, HttpServletResponse response , String limit ,String id,String start,String end) throws IOException, ParseException{
		//读取配置文件路劲
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		String interfaceUrl = ReadConfig.readValue();
		Map reqMap = new HashMap();
		OpenKey opk=new OpenKey();
		//接口编码
		reqMap.put("AUTHORITY", "YBGJJ179");
		//接口参数
		BODY body=new BODY();
		body.setDWZH(sessionIn.getDWZH());
		reqMap.put("BODY",body);
		reqMap.put("OpenKey",sessionIn.getKEY());
		String  result = opk.getOpenKey(reqMap, session);
		Map retMap = JSONUtil.toMap(result);
		retMap = (Map) retMap.get("body");
    	List retlist = (List)retMap.get("RETDATA");
		if(result != null){
			Map resMap = JSONUtil.toMap(result);
				map.put("code", 0); 
				map.put("msg", resMap.get("RETURNDESC"));;
				map.put("data",retlist);
				list.add(resMap);
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
		}
		return null;
	}
	
	@RequestMapping("/test2")
	@ResponseBody
	public String entryinterface2(HttpServletRequest request,HttpSession session, HttpServletResponse response , String limit ,String ID,String start,String end,String NY) throws IOException, ParseException{
		//读取配置文件路劲
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		String interfaceUrl = ReadConfig.readValue();
		Map reqMap = new HashMap();
		//接口编码
		reqMap.put("AUTHORITY", "YBGJJ181");
		//接口参数
		BODY body=new BODY();
		body.setID(ID);
		body.setNIANYUE(NY);
		reqMap.put("BODY",body);
		reqMap.put("OpenKey",sessionIn.getKEY());
		OpenKey opk=new OpenKey();
		String  result = opk.getOpenKey(reqMap, session);
		Map retMap = JSONUtil.toMap(result);
		retMap = (Map) retMap.get("body");
    	List retlist = (List)retMap.get("RETDATA");
		if(result != null){
			Map resMap = JSONUtil.toMap(result);
				map.put("code", 0); 
				map.put("msg", resMap.get("RETURNDESC"));;
				map.put("data",retlist);
				list.add(resMap);
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
		}
		return null;
	}
	
	@RequestMapping("/test3")
	@ResponseBody
	public String entryinterface3(HttpServletRequest request,HttpSession session, HttpServletResponse response , String limit ,String ID,String start,String end,String NY) throws IOException, ParseException{
		//读取配置文件路劲
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		String interfaceUrl = ReadConfig.readValue();
		Map reqMap = new HashMap();
		//接口编码
		reqMap.put("AUTHORITY", "YBGJJ180");
		//接口参数
		BODY body=new BODY();
		body.setDWZH(sessionIn.getDWZH());
		body.setNIANYUE(NY);
		body.setID(ID);
		reqMap.put("BODY",body);
		reqMap.put("OpenKey",sessionIn.getKEY());
		OpenKey opk=new OpenKey();
		String  result = opk.getOpenKey(reqMap, session);
		Map retMap = JSONUtil.toMap(result);
		retMap = (Map) retMap.get("body");
    	List retlist = (List)retMap.get("RETDATA");
		if(result != null){
			Map resMap = JSONUtil.toMap(result);
				map.put("code", 0); 
				map.put("msg", resMap.get("RETURNDESC"));;
				map.put("data",retlist);
				list.add(resMap);
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
		}
		return null;
	}
	

	@RequestMapping("/test4")
	@ResponseBody
	public String entryinterface4(HttpServletRequest request,HttpSession session, HttpServletResponse response , String limit ,String id,String start,String end) throws IOException, ParseException{
		//读取配置文件路劲
		SessionInfo sessionIn = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
		String interfaceUrl = ReadConfig.readValue();
		Map reqMap = new HashMap();
		OpenKey opk=new OpenKey();
		//接口编码
		reqMap.put("AUTHORITY", "YBGJJ218");
		//接口参数
		BODY body=new BODY();
		body.setDWZH(sessionIn.getDWZH());
		reqMap.put("BODY",body);
		reqMap.put("OpenKey",sessionIn.getKEY());
		String  result = opk.getOpenKey(reqMap, session);
		Map retMap = JSONUtil.toMap(result);
		retMap = (Map) retMap.get("body");
    	List retlist = (List)retMap.get("RETDATA");
		if(result != null){
			Map resMap = JSONUtil.toMap(result);
				map.put("code", 0); 
				map.put("msg", resMap.get("RETURNDESC"));;
				map.put("data",retlist);
				list.add(resMap);
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				String jsonString = JSONUtil.ToJsongString2(map);
				PrintWriter pw = response.getWriter();
				pw.write(jsonString);
		}
		return null;
	}
	
}
